package cz.data.domain.metadata.controller;

import cz.data.common.base.BaseController;
import cz.data.common.base.BaseResponse;
import cz.data.common.base.SimpleDataResponse;
import cz.data.common.validate.ValidationGroups;
import cz.data.domain.metadata.model.dto.SqlConsoleDto;
import cz.data.domain.metadata.model.vo.SqlConsoleVo;
import cz.data.domain.metadata.service.SqlConsoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/console/sql")
public class SqlConsoleController extends BaseController {

    @Autowired
    private SqlConsoleService sqlConsoleService;

    @PostMapping("/run")
    public SimpleDataResponse<List<SqlConsoleVo>> sqlRun(@RequestBody @Validated SqlConsoleDto sqlConsoleDto){
        List<SqlConsoleVo> list = sqlConsoleService.sqlRun(sqlConsoleDto);
        return new SimpleDataResponse<>(list);
    }

    @PostMapping("/stop")
    public BaseResponse sqlStop(@RequestBody @Validated({ValidationGroups.Other.class}) SqlConsoleDto sqlConsoleDto){
        sqlConsoleService.sqlStop(sqlConsoleDto);
        return BaseResponse.success();
    }
}
